from Sugarscape import *

class Government(object):

    def __init__(self, tax_rate, sugarscape):
        self.tax_rate = tax_rate
        self.sugarscape = sugarscape
        self.collective = 0

    def collect_taxes(self):
        for agent in self.sugarscape.agents:
            taken = self.tax_rate*agent.get_sugar_reserve()
            self.collective += taken
            agent.set_sugar_reserve(agent.get_sugar_reserve() - taken)
        return True

    def redistribute(self):
        tax_return = self.collective/len(self.sugarscape.agents)
        for agent in self.sugarscape.agents:
            agent.set_sugar_reserve(agent.get_sugar_reserve() + tax_return)
            self.collective -= tax_return
        return int(self.collective) == 0

if __name__=='__main__':
    a = Sugarscape(10,10)
    for i in range(10):
        a.nextstep()
    a.get_location(9, 9).set_sugar_amt(999999)
    print a
    #~ while True:
       #~ print a
       #~ a.nextstep()
       #~ time.sleep(.1)




